package practice1.annotation;

import static javax.persistence.InheritanceType.JOINED;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "account" }))
@Inheritance(strategy = JOINED)
public class User {

	@Id
	@GeneratedValue
	private Long id;

//	@NotEmpty
	private String account;
	
//	@NotEmpty
	private String username;

//	@NotEmpty
	private String password;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED", nullable = false, updatable = false)
	private Date created = new Date();
	
	@org.hibernate.annotations.Formula("(select count(*) from user)")
	private int total;
	
	// FIXME:未生效
	@Column(updatable = false, insertable = false)
	@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)
	private Date lastModified;

	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getCreated() {
		return created;
	}
	
	public int getTotal() {
		return total;
	}
	
	public Date getLastModified() {
		return lastModified;
	}
}
